const express = require("express")
const route = express.Router()
const isLoginMiddel = require("../middleware/isLoginMiddel")
const adminModel = require("../db/model/adminModel")
const {
    tokenDecode
} = require("../utils/JWT")
route.get("/loginOut", isLoginMiddel, async (req, res) => {
    const {
        adminName
    } = tokenDecode(req.headers.token, "nishilaoliu")

    try {
        
        await adminModel.updateOne({
            adminName
        }, {
            $set: {
                state: 0
            }
        })
        res.send({
            code: 10000,
            msg: "退出登录成功",
            data: null
        })
    } catch (e) {
        res.send({
            code: 10001,
            msg: "更改退出登录状态异常" + e.message,
            data: null
        })
    }
})

module.exports = route